<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生名字" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校" prop="schoolId">
        <el-select v-model="queryParams.registerSchoolId" clearable placeholder="请选择学校">
          <el-option
            v-for="item in schoolOptions"
            :key="item.schoolId"
            :label="item.schoolName"
            :value="item.schoolId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="报考层次 " prop="registerSchoolLevelId">
        <el-select v-model="queryParams.registerSchoolLevelId" clearable placeholder="请选择报考层次">
          <el-option
            v-for="item in levelOptions"
            :key="item.levelId"
            :label="calcLevelName(item)"
            :value="item.levelId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="报考专业" prop="registerSchoolProfessionId">
        <el-input
          v-model="queryParams.registerSchoolProfessionId"
          placeholder="请输入报考专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="民族" prop="nationality">
        <el-input
          v-model="queryParams.nationality"
          placeholder="请输入民族"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理" prop="sysUserId">
        <el-input
          v-model="queryParams.sysUserId"
          placeholder="代理"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="毕业证编号" prop="diplomaNo">
        <el-input
          v-model="queryParams.diplomaNo"
          placeholder="请输入毕业证编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业证学校" prop="diplomaSchool">
        <el-input
          v-model="queryParams.diplomaSchool"
          placeholder="请输入毕业证学校"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="毕业时间" prop="diplomaGraduationTime">
        <el-date-picker clearable
          v-model="queryParams.diplomaGraduationTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择毕业时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bmxt:student:add']"
        >新增</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bmxt:student:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          v-if="activeName == 0"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleAuditStatus(2)"
          v-hasPermi="['bmxt:student:remove']"
        >审核驳回</el-button>
        <el-button
          v-if="activeName == 2"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleAuditStatus(0)"
          v-hasPermi="['bmxt:student:remove']"
        >重新审批</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-if="activeName != 1"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bmxt:student:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-if="activeName == 1"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bmxt:student:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="已审核" name="1"></el-tab-pane>
      <el-tab-pane label="未审核" name="0"></el-tab-pane>
      <el-tab-pane label="驳回" name="2"></el-tab-pane>
    </el-tabs>

    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="学生主键" align="center" prop="studentId" />-->
      <el-table-column label="学生名字" align="center" prop="studentName" width="80"/>
      <el-table-column label="身份证号" align="center" prop="idCard" width="180"/>
      <el-table-column label="手机号" align="center" prop="phone"  width="120"/>
      <el-table-column label="性别" align="center" prop="sex" width="50"/>
      <el-table-column label="民族" align="center" prop="nationality"  width="60"/>
      <!--<el-table-column label="毕业证编号" align="center" prop="diplomaNo" width="120"/>-->
      <el-table-column label="前置学校" align="center" prop="diplomaSchool" width="120"/>
      <!--<el-table-column label="毕业证专业" align="center" prop="diplomaProfession" />-->
      <el-table-column label="毕业时间" align="center" prop="diplomaGraduationTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.diplomaGraduationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报考隶属" align="center" prop="registerSchoolName"  width="150"/>
      <el-table-column label="报考层次 " align="center" prop="registerSchoolLevelName" />
      <el-table-column label="专业" align="center" prop="registerSchoolProfessionName" width="150"/>
      <el-table-column label="学费/补贴金额" align="center" prop="fee"></el-table-column>
      <el-table-column label="推荐人" align="center" prop="nickName" width="100"/>
      <el-table-column label="隶属项目" align="center" prop="projectName" width="100"/>
      <el-table-column label="审核状态" align="center" prop="auditStatus" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.auditStatus == 0">未审核</span>
          <span v-if="scope.row.auditStatus == 1">审核通过</span>
          <span v-if="scope.row.auditStatus == 2">审核驳回</span>
        </template>
      </el-table-column>
      <el-table-column label="失败原因" align="center" prop="auditFailCause" width="100" v-if="activeName == '2'"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.auditStatus == 2"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bmxt:student:edit']"
          >修改
          </el-button>
          <el-button
            v-if="scope.row.auditStatus != 2"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAudit(scope.row)"
            v-hasPermi="['bmxt:student:remove']"
          >
            <span v-if="scope.row.auditStatus == 0">审核</span>
            <span v-if="scope.row.auditStatus == 1">查看</span>
          </el-button>
          <el-button
            v-if="scope.row.auditStatus == 2"
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="handleNewAudit(scope.row)"
            v-hasPermi="['bmxt:student:remove']"
          >重新审批</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @close="closeDialog">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生名字" prop="studentName">
          <el-input :disabled="auditFlag" v-model="form.studentName" placeholder="请输入学生名字" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input :disabled="auditFlag" v-model="form.idCard" placeholder="请输入身份证号" @change="calcSex"/>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-input :disabled="true" v-model="form.sex" placeholder="性别通过身份证号码自动识别" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input :disabled="auditFlag" v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="民族" prop="nationality" v-if="form.projectId == 1">
          <el-input :disabled="auditFlag" v-model="form.nationality" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="毕业证编号" prop="diplomaNo" v-if="form.projectId == 1">
          <el-input :disabled="auditFlag" v-model="form.diplomaNo" placeholder="请输入毕业证编号" />
        </el-form-item>
        <el-form-item label="前置学校" prop="diplomaSchool" v-if="form.projectId == 1">
          <el-input :disabled="auditFlag" v-model="form.diplomaSchool" placeholder="请输入毕业证学校" />
        </el-form-item>
        <!--<el-form-item label="毕业证专业" prop="diplomaProfession">
          <el-input v-model="form.diplomaProfession" placeholder="请输入毕业证专业" />
        </el-form-item>-->
        <el-form-item label="毕业时间" prop="diplomaGraduationTime" v-if="form.projectId == 1">
          <el-date-picker clearable :disabled="auditFlag"
            v-model="form.diplomaGraduationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择毕业时间">
          </el-date-picker>
        </el-form-item>
       <!-- <el-form-item label="报考学校" prop="registerSchoolId">
          <el-select v-model="form.registerSchoolId" clearable placeholder="请选择学校" :disabled="auditFlag">
            <el-option
              v-for="item in schoolOptions"
              :key="item.schoolId"
              :label="item.schoolName"
              :value="item.schoolId"
            ></el-option>
          </el-select>
        </el-form-item>-->
       <!-- <el-form-item label="报考层次 " prop="registerSchoolLevelId">
          <el-select v-model="form.registerSchoolLevelId" clearable placeholder="请选择报考层次" :disabled="auditFlag">
            <el-option
              v-for="item in levelOptions"
              :key="item.levelId"
              :label="item.levelName"
              :value="item.levelId"
            ></el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item label="报考专业" prop="schoolLevelProId">
          <!--<el-input v-model="form.registerSchoolProfessionId" placeholder="请输入报考专业id" />
          -->
          <el-cascader
            :disabled="auditFlag"
            style="width: 400px;"
            clearable
            filterable
            v-model="form.schoolLevelProId"
            :options="speOptions"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"></el-cascader>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="推荐部门" prop="deptId" v-if="! auditFlag">
              <el-form-item label="" prop="deptId">
                <treeselect v-model="deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门"/>
              </el-form-item>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐代理" prop="sysUserId">
              <!-- <el-input v-model="form.sysUserId" placeholder="请输入推荐人" :disabled="auditFlag"/>-->
              <el-select v-model="form.sysUserId"
                         :disabled="auditFlag"
                         clearable filterable placeholder="请选择代理">
                <el-option
                  v-for="item in proxyOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>



        <el-form-item label="二寸证件照" prop="remark" label-width="30">
          <FileUpload @event="handleUploadImg" :addStudentFlag="addStudentFlag" :limitNumber="Number('1')" :auditFlag="auditFlag" :fatherValue="fatherValue" :sourcesType="Number('1')" :filePathArray="certificate" v-if="DestroyIncomeStatistics==true"></FileUpload>
        </el-form-item>
        <el-form-item label="身份证正面" prop="remark" label-width="30">
          <FileUpload @event="handleUploadImg" :addStudentFlag="addStudentFlag"  :limitNumber="Number('1')" :auditFlag="auditFlag" :fatherValue="fatherValue" :sourcesType="Number('2')"  :filePathArray="idCardFront" v-if="DestroyIncomeStatistics==true"></FileUpload>
        </el-form-item>
        <el-form-item label="身份证反面" prop="remark" label-width="30">
          <FileUpload @event="handleUploadImg" :addStudentFlag="addStudentFlag"  :limitNumber="Number('1')" :auditFlag="auditFlag" :fatherValue="fatherValue" :sourcesType="Number('3')"  :filePathArray="idCardVerso" v-if="DestroyIncomeStatistics==true"></FileUpload>
        </el-form-item>
        <el-form-item label="前置毕业证" prop="remark" label-width="30">
          <FileUpload @event="handleUploadImg" :addStudentFlag="addStudentFlag"  :limitNumber="Number('1')" :auditFlag="auditFlag" :fatherValue="fatherValue" :sourcesType="Number('4')" :filePathArray="highSchoolCertificate" v-if="DestroyIncomeStatistics==true"></FileUpload>
        </el-form-item>
        <el-form-item label="证明材料全 " prop="remark" label-width="30" v-if="form.projectId == 1">
          <FileUpload @event="handleUploadImg" :addStudentFlag="addStudentFlag"  :limitNumber="Number('100')" :auditFlag="auditFlag" :fatherValue="fatherValue" :sourcesType="Number('5')"  :filePathArray="evidentiaryMaterial" v-if="DestroyIncomeStatistics==true"></FileUpload>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入" :disabled="auditFlag"  type="textarea" maxlength="500" resize="none" :rows="5"/>
        </el-form-item>

        <el-form-item label="审核意见 " prop="auditStatus" label-width="30" v-if="form.auditStatus == 0">
          <el-radio v-model="auditRadio" label="1">通过</el-radio>
          <el-radio v-model="auditRadio" label="2">驳回</el-radio>
        </el-form-item>
        <el-form-item label="驳回原因" label-width="30" prop="auditFailCause" v-if="form.auditStatus == 0 || form.auditStatus == 2">
          <el-input v-model="form.auditFailCause" :disabled="form.auditStatus == 2" placeholder="请输入审核驳回原因" type="textarea" maxlength="500" resize="none" :rows="5"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStudent, getStudent, delStudent, addStudent, updateStudent,addStudentAndFiles,treeselect } from "@/api/bmxt/student";
import { deptTreeSelect,getSubDeptUserList } from "@/api/system/user";
import FileUpload from '@/views/components/fileUpload/index'
import { allList } from "@/api/bmxt/files";
import { getAllSchoolList,getAllSchoolLevelSpeList,getQualificationCertificateList } from "@/api/bmxt/school";
import { listAllLevel } from "@/api/bmxt/level";
import {identityIdCard,identityCodeValid,validatePhone} from '@/utils/validate'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";


export default {
  name: "Student",
  // 注册子组件
  components:{
    FileUpload,
    Treeselect
  },
  watch: {
    deptId(val){
      //  调用后台接口  改变代理列表  该部门下的所有员工都需要进行显示
      val = val === undefined || val === null ? 0 : val;
      this.proxyOptions = []
      getSubDeptUserList(val).then(resp=>{
        if(resp.code == 200){
          let userList = resp.data;
          userList.forEach(item=>{
            /**
             *  proxyOptions: [{
                    value: '选项1',
                    label: '黄金糕'
                }
             */
            let user = {
              value: item.userId,
              label: item.nickName
            }
            this.proxyOptions.push(user)
          })
        }
      })
    },
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  data() {
    return {
      proxyOptions: [], // 部门下的代理列表
      deptId: null,
      // 部门树选项
      deptOptions: undefined,
      idCard: '',
      certificateFileList: [],// 二寸证件照
      idCardFrontFileList: [],// 身份证正面
      idCardVersoFileList: [],// 身份证反面
      evidentiaryMaterialFileList: [],// 证明材料
      highSchoolCertificateFileList: [],// 高中毕业证
      auditRadio: '1',
      fatherValue: {},
      value: [],
      speOptions: [],// 专业信息列表
      schoolLevelSpeOptions:[],
      qualificationCertificateOptions:[],
      auditFlag: false,
      addStudentFlag: false,
      schoolOptions:[],
      levelOptions:[],
      DestroyIncomeStatistics: false,
      certificate : [], // 证件照
      idCardFront : [], // 身份证正面
      idCardVerso : [], // 身份证反面
      highSchoolCertificate : [], // 前置学历
      evidentiaryMaterial : [], //  证明材料
      limitNumber:2,
      options: {
        uploadImg: undefined
      },
      fileList: [
        {uid: 1,name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'},
        ],
      activeName: '0',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生管理表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentName: null,
        idCard: null,
        phone: null,
        sex: null,
        nationality: null,
        diplomaNo: null,
        diplomaSchool: null,
        diplomaProfession: null,
        diplomaGraduationTime: null,
        registerSchoolId: null,
        registerSchoolLevelId: null,
        registerSchoolProfessionId: null,
        sysUserId: null,
        auditStatus: '0',
        auditFailCause: null,
        projectId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentName: [
          { required: true, message: "学生名字不能为空", trigger: "blur" }
        ],
        sysUserId: [
          { required: false, message: "推荐代理人不能为空", trigger: "blur" }
        ],
        idCard: [
          { required: true, message: "身份证号不能为空", trigger: "blur" },
          {validator: identityCodeValid, trigger: "blur", message: "请输入正确的身份证号码"}
        ],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          {validator: validatePhone, trigger: "blur"}
        ],
        registerSchoolProfessionId: [
          { required: true, message: "专业不能为空", trigger: "blur" }
        ],
       /* nationality: [
          { required: true, message: "民族不能为空", trigger: "blur" }
        ],
        diplomaNo: [
          { required: true, message: "毕业证编号不能为空", trigger: "blur" }
        ],
        diplomaSchool: [
          { required: true, message: "毕业证学校不能为空", trigger: "blur" }
        ],
        diplomaProfession: [
          { required: true, message: "毕业证专业不能为空", trigger: "blur" }
        ],
        diplomaGraduationTime: [
          { required: false, message: "毕业时间不能为空", trigger: "blur" }
        ],*/
      }
    };
  },
  created() {
    this.getList();
    this.getDeptTree();
    getSubDeptUserList(0).then(resp=>{
      let proxyOptions = resp.data;
      this.proxyOptions = []
      proxyOptions.forEach(item=>{
        let user = {
          value: item.userId,
          label: item.nickName
        }
        this.proxyOptions.push(user)
      })
    })
    // 获得学校列表
    getAllSchoolList().then(resp=>{
      this.schoolOptions = resp.data;
    })
    // 获得层次列表
    listAllLevel().then(response=>{
      this.levelOptions = response.data;
    })
    // schoolLevelSpeOptions
    getAllSchoolLevelSpeList().then(resp=>{
      this.schoolLevelSpeOptions = resp.data
      this.speOptions = resp.data
      console.log("学校级别",this.schoolLevelSpeOptions)
    })
    getQualificationCertificateList().then(resp=>{
      this.qualificationCertificateOptions = resp.data
      console.log("资格证书级别",this.qualificationCertificateOptions)
    })
  },
  methods: {
    calcLevelName(item){
      return item.levelName+"-"+item.projectName;
    },
    selectDept(){
      console.log("选择了部门",this.form.deptId);
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    handleUploadImg(uploadFileList,sourceType){
      if(sourceType == "1"){ // 证件照
        this.certificateFileList = uploadFileList;
      }else if(sourceType == "2"){ // 身份证正面
        this.idCardFrontFileList = uploadFileList;
      }else if(sourceType == "3"){ // 身份证反面
        this.idCardVersoFileList = uploadFileList;
      }else if(sourceType == "4"){ // 前置毕业证
        this.highSchoolCertificateFileList = uploadFileList;
      }else if(sourceType == "5"){ // 证明资料
        this.evidentiaryMaterialFileList = uploadFileList;
      }
    },
    handleChange(value) {
      console.log("改变的专业值是：",value)
      // form.registerSchoolId 重新赋值
      // form.registerSchoolLevelId 重新赋值
      // form.registerSchoolProfessionId 重新赋值
      if(this.form.schoolLevelProId && this.form.schoolLevelProId.length>=3){
        this.form.registerSchoolId = this.form.schoolLevelProId[0];
        this.form.registerSchoolLevelId = this.form.schoolLevelProId[1];
        this.form.registerSchoolProfessionId = this.form.schoolLevelProId[2];
      }
    },
    closeDialog(){
      this.DestroyIncomeStatistics = false
      this.queryFileData();
    },
    // 切换选项卡
    handleClick(tab, event) {
      this.queryParams.auditStatus = this.activeName
      this.getList();
    },
    /** 查询学生管理列表 */
    getList() {
      this.loading = true;
      listStudent(this.queryParams).then(response => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.queryFileData(); // 文件列表查询一下
      this.addStudentFlag = false
      this.DestroyIncomeStatistics = false
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.DestroyIncomeStatistics = false;
      this.addStudentFlag = false
      this.queryFileData();
    },
    // 表单重置
    reset() {
      this.form = {
        studentId: '',
        studentName: '',
        idCard: '',
        phone: '',
        sex: '',
        nationality: '',
        diplomaNo: '',
        diplomaSchool: '',
        diplomaProfession: '',
        diplomaGraduationTime: '',
        registerSchoolId: '',
        registerSchoolLevelId: '',
        registerSchoolProfessionId: '',
        createBy: '',
        createTime: '',
        updateBy: '',
        updateTime: '',
        remark: '',
        sysUserId: '',
        auditStatus: 0,
        auditFailCause: '',
        schoolLevelProId: '',
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.studentId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生管理";
      this.form.auditStatus = 0; // 状态修改为0
      this.auditFlag = false
      this.form.auditStatus = 1 // 只是为了隐藏审核菜单
      this.DestroyIncomeStatistics = true
      this.addStudentFlag = true
      this.certificate = []
      this.idCardFront = []
      this.idCardVerso = []
      this.highSchoolCertificate = []
      this.evidentiaryMaterial = []
    },
    handleNewAudit(row){ // 审批学生资料
      this.form.auditStatus = 0; // 状态修改为0
      this.addStudentFlag = false
      this.$modal.confirm('是否确认重新提交姓名为"' +row.studentName + '"的学生资料？').then(() => {
        updateStudent(this.form).then(response => {
          this.open = false;
          this.getList();
        })
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    /*操作审核*/
    async handleAudit(row){
      this.loading = true;
      this.addStudentFlag = false
      this.auditRadio = '1'
      // 只有学生信息处于待审核和驳回状态 才可以编辑
      if(row.auditStatus == '0'){ // 审核
        this.auditFlag = true
      }else{
        this.auditFlag = true
      }
      this.DestroyIncomeStatistics = false;
      this.reset();
      const studentId = row.studentId || this.ids
      // 获得文件信息
      let queryParams = {
        studentId: studentId,
      }
      await allList(queryParams).then(resp=>{
        this.certificate = []
        this.idCardFront = []
        this.idCardVerso = []
        this.highSchoolCertificate = []
        this.evidentiaryMaterial = []
        if(resp.code == 200 && resp.data!=null && resp.data.length>0){
          resp.data.forEach(item=>{
            let data = {filePath: item.filePath ,fileId: item.fileId}
            if(item.fileTypeId == '1'){ // 证件照
              this.certificate.push(data)
            }else if(item.fileTypeId == '2'){ // 身份证正面
              this.idCardFront.push(data)
            }else if(item.fileTypeId == '3'){ // 身份证反面
              this.idCardVerso.push(data)
            }else if(item.fileTypeId == '4'){ // 前置学历
              this.highSchoolCertificate.push(data)
            }else if(item.fileTypeId == '5'){ // 证明材料
              this.evidentiaryMaterial.push(data)
            }
          })
        }
      })
      await getStudent(studentId).then(response => {
        this.form = response.data;
        // 组装一个折叠选择框
        // this.form.schoolLevelProId = this.form.registerSchoolId+','+this.form.registerSchoolLevelId+','+this.form.registerSchoolProfessionId;
        this.form.schoolLevelProId = [];
        this.form.schoolLevelProId.push(this.form.registerSchoolId.toString())
        this.form.schoolLevelProId.push(this.form.registerSchoolLevelId.toString())
        this.form.schoolLevelProId.push(this.form.registerSchoolProfessionId.toString())
        console.log("审核-个人选择专业",this.form.schoolLevelProId);
        console.log("审核-所有专业",this.schoolLevelSpeOptions);
        if(this.form.projectId == 1){// 学历专业
          this.speOptions = this.schoolLevelSpeOptions
        }else if(this.form.projectId == 2){ // 人社资格证书
          this.speOptions = this.qualificationCertificateOptions
        }
        this.deptId = this.form.deptId //设置部门树显示该部门
        this.open = true;
        this.title = "学生审核管理";
        this.DestroyIncomeStatistics = true;
      });
      this.loading = false;
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      this.loading = true;
      this.fatherValue = row;
      this.DestroyIncomeStatistics = false;
      this.addStudentFlag = false
      this.auditFlag = false
      this.reset();
      const studentId = row.studentId || this.ids
      // 获得文件信息
      let queryParams = {
        studentId: studentId,
      }
      await allList(queryParams).then(resp=>{
        this.certificate = []
        this.idCardFront = []
        this.idCardVerso = []
        this.highSchoolCertificate = []
        this.evidentiaryMaterial = []
        if(resp.code == 200 && resp.data!=null && resp.data.length>0){
          resp.data.forEach(item=>{
            let data = {filePath: item.filePath ,fileId: item.fileId}
            if(item.fileTypeId == '1'){ // 证件照
              this.certificate.push(data)
            }else if(item.fileTypeId == '2'){ // 身份证正面
              this.idCardFront.push(data)
            }else if(item.fileTypeId == '3'){ // 身份证反面
              this.idCardVerso.push(data)
            }else if(item.fileTypeId == '4'){ // 前置学历
              this.highSchoolCertificate.push(data)
            }else if(item.fileTypeId == '5'){ // 证明材料
              this.evidentiaryMaterial.push(data)
            }
          })
        }
      })
      await getStudent(studentId).then(response => {
        this.form = response.data;
        // this.form.schoolLevelProId = this.form.registerSchoolId+','+this.form.registerSchoolLevelId+','+this.form.registerSchoolProfessionId;
        this.form.schoolLevelProId = [];
        this.form.schoolLevelProId.push(this.form.registerSchoolId.toString())
        this.form.schoolLevelProId.push(this.form.registerSchoolLevelId.toString())
        this.form.schoolLevelProId.push(this.form.registerSchoolProfessionId.toString())
        console.log("修改-个人选择专业",this.form.schoolLevelProId);
        if(this.form.projectId == 1){// 学历专业
          this.speOptions = this.schoolLevelSpeOptions
        }else if(this.form.projectId == 2){ // 人社资格证书
          this.speOptions = this.qualificationCertificateOptions
        }
        this.deptId = this.form.deptId // 设置部门树显示该部门
        this.open = true;
        this.title = "修改学生管理";
        this.DestroyIncomeStatistics = true;
      });
      this.loading = false;
    },
    queryFileData(){
      const studentId = this.ids
      // 获得文件信息
      let queryParams = {
        studentId: studentId,
      }
    },
    calcSex(){
      let isIdcard = identityIdCard(this.form.idCard);
      if(isIdcard){
        if (parseInt(this.form.idCard.substr(16, 1)) % 2 == 1) {
          this.form.sex = '男';
        } else {
          this.form.sex = '女';
        }
      }else{
        this.form.sex = '不详';
      }
    },
    /** 提交按钮 */
    submitForm() {
      // return this.$modal.msgSuccess(this.form.sysUserId == '');
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.studentId != null && this.form.studentId != '') {
            // 是否是驳回信息
            if(this.form.auditStatus == 0 && this.auditRadio == '1'){ // 同意
              this.$modal.confirm('是否确认学生资料审核通过？').then(()=> {
                this.form.auditStatus = 1;
                updateStudent(this.form).then(response => {
                  this.$modal.msgSuccess("审核成功");
                });
              }).then(() => {
                this.open = false;
                this.getList();
              }).catch(() => {});
            }else if(this.form.auditStatus == 0 && this.auditRadio == '2'){ //驳回
              if(this.form.auditFailCause == null || this.form.auditFailCause == ''){
                return  this.$modal.msgError("请填写驳回原因");
              }
              this.form.auditStatus = this.auditRadio;
              updateStudent(this.form).then(response => {
                this.$modal.msgSuccess("审核成功");
                this.open = false;
                this.getList();
              });
            }else if (this.form.auditStatus == 2){ // 修改数据 审核驳回的记录
              updateStudent(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
            // 数据组成
            let formData = new FormData();
            formData.append("studentName",this.form.studentName)
            formData.append("nationality",this.form.nationality)
            if( ! this.form.idCard){
              this.form.idCard = this.idCard;
            }
            formData.append("idCard",this.form.idCard)
            if(! this.form.sex){
              this.calcSex();
              formData.append("sex",this.form.sex)
            }else{
              formData.append("sex",this.form.sex)
            }
            formData.append("phone",this.form.phone)
            formData.append("sysUserId",this.form.sysUserId)
            formData.append("diplomaGraduationTime",this.form.diplomaGraduationTime)
            formData.append("diplomaNo",this.form.diplomaNo)
            formData.append("diplomaSchool",this.form.diplomaSchool)
            formData.append("registerSchoolProfessionId",this.form.registerSchoolProfessionId)
            // 证件照
            if(this.certificateFileList.length > 0){
              this.certificateFileList.forEach(file=>{
                formData.append("certificateFile",file)
              })
            }
            // 身份证正面
            if(this.idCardFrontFileList.length > 0){
              this.idCardFrontFileList.forEach(file=>{
                formData.append("idCardFrontFile",file)
              })
            }
            // 身份证反面
            if(this.idCardVersoFileList.length > 0){
              this.idCardVersoFileList.forEach(file=>{
                formData.append("idCardVersoFile",file)
              })
            }
            // 前置学历 highSchoolCertificateFile
            if(this.highSchoolCertificateFileList.length > 0){
              this.highSchoolCertificateFileList.forEach(file=>{
                formData.append("highSchoolCertificateFile",file)
              })
            }
            // 证明材料
            if(this.evidentiaryMaterialFileList.length > 0){
              this.evidentiaryMaterialFileList.forEach(file=>{
                formData.append("evidentiaryMaterialFiles",file)
              })
            }
            addStudentAndFiles(formData).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }else{
          this.$modal.msgError('请补全资料再提交')
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const studentIds = row.studentId || this.ids;
      this.$modal.confirm('是否确认删除学生管理编号为"' + studentIds + '"的数据项？').then(function() {
        return delStudent(studentIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleAuditStatus(auditStatus) { // 审核处理  驳回和重新审核
      const studentIds = this.ids;
      let statusDesc = auditStatus ==2 ? '驳回':'重新审核';
      this.$modal.confirm('是否确认'+statusDesc+'学生编号为"' + studentIds + '"的数据项？').then(()=> {
        this.form.auditStatus = auditStatus;
        this.form.studentId = studentIds[0]
        updateStudent(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
        });
      }).then(() => {
        // 跳转到相应的操作tab
       /* this.activeName = auditStatus.toString()
        this.queryParams.auditStatus = auditStatus*/
        this.getList();
      }).catch(err => {
        console.log(err)
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bmxt/student/export', {
        ...this.queryParams
      }, `student_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
  /deep/ .el-table .el-table__body td .cell:empty::after,
  .el-table .el-table__body td .cell > span:empty::after,
  .el-table .el-table__body td .cell .approval:empty::after,
  .el-table .el-table__body td .cell div:empty::after,
  .el-table .el-table__body td .cell .line-limit-length:empty::after {
    content: "无";
  }

</style>
